package com.ymatou.iapi.listpriceq.service;

import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymttest.business.YmatouAutoTestCall;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.MapUtil;

public class GetCatalogPriceListByDeliveryTradeIsolationCall extends YmatouAutoTestCall{

	private static String opurl ="api/Price/GetCatalogPriceListByDeliveryExtra";
	
	public GetCatalogPriceListByDeliveryTradeIsolationCall() {
		super(EnvSetup.getSystemUrl("listpriceq"),opurl,"POST","JSON");
	}


	@Override
	public void addDefHeader() {
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	public JSONObject callAndGetReturnData(int buyerId,Map<String,Integer> catalogsMap){
		
		try {
			JSONArray catalogArray = new JSONArray();
			catalogsMap.forEach((x,y)->{
				JSONObject tmp = new JSONObject();
				
				try {
					tmp.put("CatalogId", x);
					tmp.put("DeliveryType", y);
				} catch (JSONException e) {
					e.printStackTrace();
				}
				catalogArray.put(tmp);
			});
			
			JSONObject requestBean = this.getJsonBean(null);
			requestBean.put("CatalogList", catalogArray);
			JsonBeanHelper.updateJsonBean(requestBean, MapUtil.hashMap("BuyerId", buyerId));
			
			return callAndGetReturnData(requestBean);
			
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return null;
		
		
		
		
	}
	
	public static void main(String[] args) {
		new GetCatalogPriceListByDeliveryTradeIsolationCall().callAndGetReturnData(3383,MapUtil.hashMap("1ca0269b-e6a2-439b-bb66-3b6acdb3604c", 2));
	}



}
